home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / DOCS / AMOSDOC.LHA / AmosHyperBook.dms / in.adf / Manual / ALLIANCE-18 / ALLIANCE-18
Encoding:
Text File  |  1992-03-20  |  6.6 KB  |  219 lines

  1.  
  2.  
  3.  
  4.  
  5.                            18: THE KEYBOARD                                249
  6.                       --------------------------
  7.  
  8. AMOS Basic provides you with dozens of useful keyboard commands. These
  9. can be used in anything from an Arcade game to an Adventure. It's even
  10. possible to write a fully fledged wordprocessor entirely in AMOS Basic!
  11.  
  12.  
  13.  
  14.                  =INKEY$ (function to get a keypress)
  15.  
  16. k$=INKEY$
  17.  
  18. This function checks whether the user has pressed a key, and returns
  19. its value in the string k$
  20.  
  21.   Note the INKEY$ command doesn't wait your input in any way. If the
  22. user hasn't entered a character, INKEY$ will simply return an empty
  23. string "".
  24.  
  25.   INKEY$ is only capable of reading keys which return a specific Ascii
  26. character from the keyboard. Ascii is a standard code used to represent
  27. all the characters which can be printed on the screen.
  28.  
  29.   It's important to realise that some keys, like HELP button or the
  30. function keys, use a rather different format. If INKEY$ detects such a
  31. key, it will return a character with a value of zero (CHR$(0)). You can
  32. now find the internal scan code of this key using a separate SCAN CODE
  33. function.
  34.  
  35.  
  36.  
  37.                =SCANCODE (input the scancode of the last
  38.                         key input with INKEY$)
  39.  
  40. s=SCANCODE
  41.  
  42. SCANCODE returns the internal scancode of a key which has previously
  43. entered using the INKEY$ function. This allows you to check for keys
  44. which do not produce a character from the keyboard, such as HELP or
  45. TAB. Type the following small example:
  46.  
  47.       Do
  48.         While K$=""
  49.           K$=Inkey$
  50.         Wend
  51.         If Asc(K$)=0 Then Print "You pressed a key with no ASCII Code"
  52.         Print "The Scancode Is";Scancode
  53.         K$=""
  54.       Loop
  55.  
  56.  
  57.                 =KEY STATE (test whether an individual                     250
  58.                          key has been pressed)
  59.  
  60. t=KEY STATE(s)
  61.  
  62. Check if a specific button has been pressed on the Amiga's keyboard. s
  63. is the internal scancode of the key you want to check. If this key is
  64. currently being depressed then KEY state will return a value of true
  65. (-1), otherwise the result will be false (0).
  66.  
  67.  
  68.  
  69.                    =KEY SHIFT (return the status of
  70.                             the shift keys)
  71.  
  72. keys=KEY SHIFT
  73.  
  74. KEY SHIFT returns the current status of the various control keys. These
  75. keys such as SHIFT or Alt cannot be detected using the standard INKY$
  76. or SCANCODE system. But you can easily test for any combination of
  77. control keys with just a single call to the KEY SHIFT function. "keys"
  78. is a bit map in the following format:
  79.  
  80.         Bit  Key Tested         Notes
  81.         ---  ----------         -----
  82.          0   Left SHIFT
  83.          1   Right SHIFT
  84.          2   Caps Lock          Either ON or OFF
  85.          3   CTRL
  86.          4   Left ALT
  87.          5   Right ALT
  88.          6   Left AMIGA         C= key on some keyboards
  89.          7   Right AMIGA
  90.  
  91. If a bit is set to a one, then the associated button has been held down
  92. by the user.
  93.  
  94.  
  95.  
  96.                     INPUT$(n) (function to input n
  97.                        characters into a string)
  98.  
  99. INPUT$ enters n characters straight from the keyboard, waiting for each
  100. one in turn. As with INKEY$, these characters are not echoed onto the
  101. screen.
  102.  
  103.   x$ is a string variable which will be loaded with your new
  104. characters. n holds the number of characters to be entered. Example:
  105.  
  106.         Clear Key : Print "Type In Then Characters"
  107.         C$=INPUT$(10) : Print "You entered ";C$
  108.  
  109. This insturction *not* the same as the standard INPUT command. The two
  110. instuctions are completely different. Also note that there's a special
  111. version of INPUT$ which can be used to read your characters from the
  112. disc.
  113.  
  114.  
  115.  
  116.                      WAIT KEY(wait for a keypress)                         251
  117.  
  118. WAIT KEY
  119.  
  120. Waits for a single keypress.
  121.  
  122.  
  123.  
  124.                   KEY SPEED (change key repeat speed)
  125.  
  126. KEY SPEED lag,speed
  127.  
  128. KEY SPEED lets you tailor the speed of the keyboard to your own
  129. particular taste. The new speed will be used for every part of the AMOS
  130. system, including the editor.
  131.  
  132.   "lag" is the time in 50th of a second between pressing a key, and the
  133. start of the repeat sequence.
  134.  
  135.   "speed" is the delay of second between each successive character.
  136.  
  137.  
  138.  
  139.                 CLEAR KEY (initialise keyboard buffer)
  140.  
  141. CLEAR KEY
  142.  
  143. Whwnever you enter a character from the keyboard, its Ascii code is
  144. placed in an area of memory known as the keyboard buffer. It is this
  145. buffer that is sampled by the INKEY$ function to get your key presses.
  146.  
  147.   CLEAR key erases this buffer completely, and returns your keyboard to
  148. this original state. It's especially helpful at the start of a program,
  149. as the buffer may well be full of unwanted information. You can also
  150. call it immediately before a WAIT KEY comand to ensure that the program
  151. waits for a fresh keypress before preceding.
  152.  
  153.  
  154.  
  155.             PUT KEY (Put a string into the keyboard buffer)                252
  156.  
  157. PUT KEY a$
  158.  
  159. Loads a string a characters directly into the keyboard buffer. Carriage
  160. returns can be included using a CHR$(13) character.
  161.  
  162.   The most common use of PUT KEY is to set up defaults for your input
  163. routines. Here's a demonstration:
  164.  
  165.         Do
  166.           Put Key "No"
  167.           Input "Another Game";A$
  168.           If A$="No" Then Exit
  169.         Loop
  170.  
  171.  
  172.  
  173. Input/Output
  174. ============
  175.  
  176.                  INPUT (load a value from the user and
  177.                           put it a variable)
  178.  
  179. INPUT
  180.  
  181. Provides you with a standard way of entering information into one or
  182. more variables. There are two possible formats for this instrucion:
  183.  
  184. INPUT vars[;]
  185.  
  186. Enters a list of variables directly from the keyboard. "var" can
  187. contain any set of variables you like, separated by commas. A question
  188. mark will be automatically displayed at the current cursor position.
  189.  
  190. INPUT "Prompt";variable list[;]
  191.  
  192. Prints out the "prompt" string before entering your information. Note
  193. that you must always place a semi-colon between your text and the
  194. variable list. You are *not* allowed to use a comma for this purpose.
  195.  
  196.   The optional semi-colon ";" at the end of your variable list
  197. specifies that the text cursor will not be affected by the INPUT
  198. instruction, and will retain its original position after the data has
  199. been entered.
  200.  
  201.   When you execute one of these commands, Basic will wait for you enter
  202. the required information from the keyboard. Each variable in your list
  203. must be matched by a single value from the user. These values must be
  204. of the same as your original values, and should be separated by commas.
  205.  
  206.  
  207.  
  208.                       LINE INPUT (input a list of                          253
  209.                    variables separated by a Return)
  210.  
  211. LINE INPUT "Prompt";variable list[;]
  212.  
  213. Line input is exactly same as INPUT, except that it uses a Return
  214. instead of a comma to separate each value you enter from the keyboard.
  215.  
  216.  
  217.  
  218.  
  219.